<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <link type="text/css" rel="stylesheet" th:href="@{/css/all.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/plugin/zTree_v3-master/css/metroStyle/metroStyle.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css}"/>
<!--
    <script language="JavaScript" th:src="@{/js/all.js}" src="js/all.js"></script>
-->

    <script language='JavaScript' th:src='@{/plugin/jQuery/jQuery-2.2.0.min.js}'></script>
    <script language='JavaScript' th:src="@{/ajax/layer/layer.min.js}"></script>
    <script language='javascript' th:src='@{/js/constant.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/jQuery/jquery.mousewheel.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/jquery-easyui-1.5.1/jquery.easyui.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap/js/bootstrap.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-table/bootstrap-table.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/adminLTE/js/app.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/lobibox/dist/js/lobibox.js}'></script>
    <script language='JavaScript' th:src='@{/js/network.js}'></script>
    <script language='JavaScript' th:src='@{/js/common.js}'></script>
    <script language='JavaScript' th:src='@{/js/public.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-datetimepicker/js/moment-with-locales.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/iCheck/icheck.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/zTree_v3-master/js/jquery.ztree.core.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/zTree_v3-master/js/jquery.ztree.excheck.min.js}'></script>
    <script language='JavaScript' th:src='@{/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js}'></script>

    <style type="text/css">
        .form-group{
            margin-top: 5px;
            margin-bottom: 5px;
        }
        #user-role-table td {
           border-left-width: 0px !important;
            border-right-width: 0px !important;
         }

        #user-role-table th {
            border-left-width: 0px !important;
            border-right-width: 0px !important;
        }

    </style>
</head>
<body class="body-contrainner fadeInUp">
<div class="box box-info">
    <div class="box-header with-border">
        <form id="form-search" class="form-inline has-info">
            <div class="form-group">
                <label class="control-label">模块名称</label>
                <input type="text" id="name" name="Log_moduleName@@like" class="form-control" placeholder="请输入模块名称">
            </div>
            <div class="form-group">
                <label class="control-label">用户名称</label>
                <input type="text" id="userName" name="Log_User@@like" class="form-control" placeholder="请输入用户名称">
            </div>
        </form>
        <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
        </div>
    </div>
    <div class="box-body" style="padding-top: 0px;">
        <div id="tool-bar">
            <button id="btn-search" type="button" class="btn btn-info"><i class="fa fa-search margin-r-5"></i>查询</button>
            <button id="btn-del" type="button" class="btn btn-default"><i class="fa fa-remove margin-r-5"></i>删除</button>
            <button id="btn-export" type="button" class="btn btn-default"><i class="fa fa-download margin-r-5"></i>导出</button>
        </div>
        <table id="data-table" class="table table-bordered" data-striped="true" data-pagination="true" data-search="false"
               data-search-on-enter-key="true" data-show-columns="true" data-show-refresh="true"
               data-show-toggle="true" 	data-show-pagination-switch="true" data-id-field="id"
               data-unique-id="id" data-click-to-select="true" data-side-Pagination="server"
               data-cache="false" data-method="get" data-toolbar="#tool-bar" data-query-params="getParam">
            <thead>
            <tr id="tab">

            </tr>
            </thead>
        </table>
    </div>
</div>


<div id="input-modal2" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width:300px;max-width: 400px;  width: 70%;" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <center><span  style="font-size:20px;">导出字段选择</span></center>
            </div>

            <div class="modal-body" id="messageBody" style="height:340px; overflow:scroll;text-align: center;">
                <div class="btn-group" id="checks" data-toggle="buttons" style="text-align: center;">


                </div>
            </div>
            <div class="modal-footer">
                <center>
                <button id="btn-selectAll" type="button" class="btn btn-default" >反选</button>
                <button id="btn-cancel2" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn-save2" type="button" class="btn btn-info">保存</button>
                </center>
            </div>
        </div>
    </div>
</div>

<script language="JavaScript">
    var myTableName='sys_systemlog';
   ajax.postData(publicData.urls.system.getFields, {'tableName':myTableName}, function (data) {
       var html='<th data-field="state" data-checkBox="true">#</th>';
       html+='<th data-field="rowNum" data-align="left" data-halign="left" data-valign="middle" data-formatter="bootstrapFormatter.rowNumFormatter">序号</th>'

       for(var i = 0;i < data.length;++i){
           var codeAndInfo = data[i];
           if(codeAndInfo.column_name == "id"){

           }else{
               html+='<th data-field="'+codeAndInfo.column_name+'" data-align="left" data-halign="left"'
                   +'data-valign="middle" data-sortable="true">'+codeAndInfo.column_comment+'</th>';
           }
       }
       $("#tab").html(html);
       if ( data!=null||data!="") {
           $("#data-table").bootstrapTable("refresh");
           $("#data-table").bootstrapTable({url: publicData.urls.system.getPage});
       }else{
           $("#tab").html("不存在");
       }
   });
   var bootStrap={}
   //这个携带页面查询参数
    function getParam(params) {
        var total=commonTools.getBootstrapParams(params, $("#form-search"))
        total.params.tableName=myTableName;
        if(total.sort==undefined){
            total.sort='Log_occurrTime';
            total.order='desc';
        }
        bootStrap=total;
        return total;
    }

    $("#btn-search").click(function () {
        $("#data-table").bootstrapTable("refresh");
    });

    $("#btn-del").click(function () {
        var datas = $("#data-table").bootstrapTable("getSelections");
        if (datas.length == 0) {
            messageBox.info("请选择要删除的数据");
            return;
        }
        var ids="";
        for(var i=0;i<datas.length;i++){
            ids+=datas[i].id
            if(i==datas.length-1){

            }else{
                ids+=",";
            }
        }
        messageBox.confirm("您确认要删除该数据吗？", function(){
            ajax.postData(publicData.urls.system.del, {"id": ids,"tableName":myTableName}, function () {
                messageBox.success("删除成功");
                $("#data-table").bootstrapTable("refresh");
            });
        }, undefined);
    });


    //==============导出模块

   $("#btn-export").click(function () {
       $("#checks").html("");
       ajax.postData(publicData.urls.system.getFields, {'tableName':myTableName}, function (data) {
           var bb="";
           for(var i = 0;i < data.length;++i){
               var codeAndInfo = data[i];
               bb+="<label class='btn btn-default' style='width: 80%;margin-bottom: 5px;margin-left: 10%;margin-right: 10%;'>"
                   +"<input  name='columnCheckBoxs'    value='"+codeAndInfo.column_name+"' type='checkbox'>"+codeAndInfo.column_comment
                   +"</label>"
           }
           $("#checks").html(bb);
       })
      $("#input-modal2").modal("show");
   })

   $("#btn-save2").click(function () {
       var obj = document.getElementsByName("columnCheckBoxs");
       var check_val =[];
       var columnStr="";
       for(var k in obj){
           if(obj[k].checked)
               columnStr+=obj[k].value+",";
       }
       columnStr=columnStr.substring(0,columnStr.length-1)
       bootStrap.columnStr=columnStr;
       var message=JSON.stringify(bootStrap);
       message=message.replace(/\{/g,"(")
       message= message.replace(/\}/g,")")
       console.log(publicData.urls.system.exportMessage)
       window.location.href=publicData.urls.system.exportMessage+"?message="+message
       $("#input-modal2").modal("hide");
       messageBox.success("删除成功");

   })

   $("#btn-selectAll").click(function () {
       $("#checks .btn").button('toggle')
   })




</script>
</body>
</html>